package objectio;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;

public class ReadFileToObject {
	
	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("person.data")));
		ObjectOutputStream objectOutputStream = new  ObjectOutputStream(new FileOutputStream("person_copy.data"));
		
		String line = null;
		Person person = null;
		String[] msg = null;
		
		while((line = reader.readLine()) != null){
			System.out.println(line);
			msg = line.split("\t");
			person = new Person();
			person.setId(Integer.valueOf(msg[0]));
			person.setName(msg[1]);
			person.setAge(Integer.valueOf(msg[2]));
			System.out.println(person.toString());
			objectOutputStream.writeObject(person);
		}
		objectOutputStream.writeObject(null);
	}
	
}
